<template>
  <div class="chooseSettle">
    <el-dialog
        :title="title"
        :visible.sync="dialogVisible"
        @closed="handleClose"
        width="60%"
    >
      <el-alert :title="alertTitle" type="error" :closable="false"></el-alert>
      <div class="ccui-advanced-search-wrapper">
        <el-search
            ref="search"
            :formProp="formData"
            :isShowSearch="true"
            :selectClear="true"
            class="ccui-highsearch"
            :spoNum="2"
            @search="search"
        >
          <template slot="search">
            <el-input
                v-model="formData.warehouseName"
                searchLabel="仓库名称"
                @blur="handleTrim('warehouseName')"
                clearable
                placeholder="请输入仓库名称模糊查询"
            ></el-input>
            <el-input
                v-model="formData.warehouseCode"
                searchLabel="仓库编号"
                clearable
                placeholder="请输入仓库编号模糊查询"
            ></el-input>
            <el-input
                v-model="formData.projectName"
                searchLabel="项目名称"
                clearable
                placeholder="请输入项目名称模糊查询"
            ></el-input>
            <el-input
                v-model="formData.accountingOrgan"
                searchLabel="核算组织"
                clearable
                placeholder="请输入核算组织模糊查询"
            ></el-input>
            <el-input
                v-model="formData.warehousePlace"
                searchLabel="库存地点"
                clearable
                placeholder="请输入库存地点模糊查询"
            ></el-input>
            <el-input
                v-model="formData.warehousePhone"
                searchLabel="联系电话"
                clearable
                placeholder="请输入联系电话模糊查询"
            ></el-input>
          </template>
          <el-input
              v-model="formData.warehouseName"
              searchLabel="仓库名称"
              @blur="handleTrim('warehouseName')"
              placeholder="请输入仓库名称模糊查询"
              clearable
              slot="searchItem1"
          ></el-input>
          <el-input
              v-model="formData.warehouseCode"
              searchLabel="仓库编号"
              placeholder="请输入仓库编号模糊查询"
              clearable
              slot="searchItem2"
          ></el-input>
          <el-input
              v-model="formData.projectName"
              searchLabel="项目名称"
              placeholder="请输入项目名称模糊查询"
              clearable
              slot="searchItem3"
          ></el-input>
          <el-input
              v-model="formData.accountingOrgan"
              searchLabel="核算组织"
              placeholder="请输入核算组织模糊查询"
              clearable
              slot="searchItem4"
          ></el-input>
          <el-input
              v-model="formData.warehousePlace"
              searchLabel="库存地点"
              placeholder="请输入库存地点模糊查询"
              clearable
              slot="searchItem5"
          ></el-input>
          <el-input
              v-model="formData.warehousePhone"
              searchLabel="联系电话"
              placeholder="请输入联系电话模糊查询"
              clearable
              slot="searchItem6"
          ></el-input>
        </el-search>
      </div>
      <div class="ccui-multifunctional-table-wrapper">
        <el-table
            :dataObj="singleSelectData"
            :data="purchaseListList"
            class="ccui-form-child-table"
            border
            width="600px"
            style="margin-bottom: 20px"
            max-height="800px"
            :fit="true"
        >
          <el-table-column
              show-overflow-tooltip
              label="序号"
              type="index"
              align="center"
          />

          <el-table-column
              show-overflow-tooltip
              prop="warehouseCode"
              label="仓库编号"
              width="120"
          >
          </el-table-column>

          <el-table-column
              show-overflow-tooltip
              prop="warehouseName"
              label="仓库名称"
          >
          </el-table-column>
          <el-table-column
              show-overflow-tooltip
              prop="projectName"
              label="项目名称"
          />
          <el-table-column
              show-overflow-tooltip
              prop="accountingOrgan"
              label="核算组织"
          />
          <el-table-column
              show-overflow-tooltip
              prop="warehousePlace"
              label="库存地点"
          >
          </el-table-column>

          <el-table-column
              show-overflow-tooltip
              prop="warehousePhone"
              label="联系电话"
              width="150"
          >
          </el-table-column>

          <el-table-column label="操作" width="50">
            <template slot-scope="{ row }">
              <el-button size="mini" type="text" @click="handlecheck(row)"
              >选择
              </el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listScWarehouse} from "../api";
import {getSessionItem} from "@/basa/utils";

export default {
  props: {
    reportInOrgName: {
      type: String
    },
    reportInOrgId: {
      type: Number
    },
    isTrue: {
      type: Boolean
    }
  },
  data() {
    return {
      title: "选择原仓库",
      alertTitle: "如需维护仓库信息，请去仓库维护功能菜单进行操作!",
      purchaseListList: [],
      singleSelectData: [],
      dialogVisible: false,
      formData: {
        warehouseCode: "", //仓库名称
        warehouseName: "", //仓库编号
        projectName: "", //项目名称
        accountingOrgan: "", //核算组织
        warehousePlace: "", //库存地点
        warehousePhone: "" //联系电话
      },
      formDataSearch: {
        warehouseName: "",
        warehouseCode: "",
        projectName: "",
        accountingOrgan: "",
        warehousePhone: "",
        warehousePlace: ""
      }
    };
  },
  methods: {
    // 清空名称空格
    handleTrim(key) {
      this.$set(
          this.formData,
          key,
          this.formData[key].replace(/(^\s*)|(\s*)$/g, "")
      );
    },
    showContractList() {
      this.dialogVisible = true;
      this.getContractList(this.formData);
    },
    getContractList(data) {
      listScWarehouse({
        ...data,
        reportInOrgId: this.reportInOrgId
      }).then(res => {
        this.purchaseListList = res.data.data;
      });
    },
    handlecheck(row) {
      this.$store.commit("setMoveInventoryCount", "");
      this.$store.commit("setMoveInventoryMoney", "");
      this.$emit("getRow", row);
      this.$bus.$emit("getHouseId", row);
      this.dialogVisible = false;
      this.$bus.$emit("resetPurchase", []);
    },
    handleClose() {
    },
    // 高级搜索展开按钮
    search(searchData) {
      this.formDataSearch = JSON.parse(JSON.stringify(searchData));
      this.formDataSearch.reportOrgId = getSessionItem("userInfo", "orgId");
      this.getContractList(this.formDataSearch);
    }
  }
};
</script>

<style lang="scss" scoped>
.chooseSettle {
  display: inline-block;
}

/deep/ .el-single-select
.el-dialog__wrapper
.el-dialog
.el-dialog__body
.el-dialog-box
.dialog-top {
  justify-content: space-between;
}

/deep/ .el-table__body-wrapper {
  max-height: 230px !important;
}

/deep/ .label {
  display: inline-block;
  width: 130px !important;
  text-align: right;
}

// /deep/ .el-dialog__footer {
//   border-top: none;
// }
// /deep/ .el-table td,
// .el-table th {
//   padding: 5px 0 !important;
// }
// /deep/ .disabledBtn {
//   // border: 1px solid #999 !important;
//   span {
//     color: #999 !important;
//   }
// }

/deep/ .ccui-advanced-search-wrapper .el-search {
  margin-top: 15px;
}

/deep/ .el-form-item {
  margin-bottom: 15px !important;
}

/deep/ .el-search .el-searchs {
  float: none;
}

/deep/ .el-searchs-box {
  margin: 0 auto;
}

// /deep/ .el-dialog__header .el-dialog__title{
//   line-height: 30px !important;
// }
/deep/ .ccui-search-wrapper .el-searchs .el-input {
  width: 200px !important;
}
</style>
